<?php

namespace App\Providers;

use App\Http\Controllers\Api\Agent\AgentController;
use App\Interfaces\agent\AgentInterFace;
use App\Interfaces\MapInterFace;
use App\Interfaces\MsgInterFace;
use App\Interfaces\WorkshopInterFace;
use App\model\User;
use App\Repository\Agent\AgentRepository;
use App\Repository\MsgRepository;
use App\Repository\WorkShopRepository;
use App\Service\TengxunMapService;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        /**
         * 设置数据库字段长度191
         */
        \Schema::defaultStringLength(191);

      /*  \DB::listen(function($query) {
            $bindings = $query->bindings;
            $sql = $query->sql;
            foreach ($bindings as $replace) {
                $value = is_numeric($replace) ? $replace : "'" . $replace . "'";
                $sql = preg_replace('/\?/', $value, $sql, 1);
            }
            \Log::info($sql);
        });*/



        }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {



        $this->app->bind(WorkshopInterFace::class,WorkShopRepository::class);
        $this->app->bind(AgentInterFace::class,AgentRepository::class);
        $this->app->bind(MsgInterFace::class,MsgRepository::class);
        $this->app->bind(MapInterFace::class,TengxunMapService::class);
        \Validator::extend('slider', function ($attribute, $value, $parameters, $validator) {
            if (count(explode(',',$value))<15){
                return false;
            }
            return true;
        });
        \Validator::extend('contact', function ($attribute, $value, $parameters, $validator) {

            if (count(explode(',',$value))<1||$value=="[]"){
                return false;
            }
            return true;
        });

    }
}
